package com.hepinghospital.user.util

import com.rest.response.MaterialBean
import com.rest.response.NursingOrderResponse
import java.util.*

/**
 *
 * @Description: 处理耗材数据类
 * @Author: lzp
 * @CreateDate: 2022/4/11 11:19
 * @UpdateRemark: 更新说明
 */
object DataUtil {

    fun handleConsumeMaterials(data: List<NursingOrderResponse.ConsumeMaterialsBean>): List<MaterialBean> {
        if (data.isEmpty()) return ArrayList()

        val materialBeanArrayList = ArrayList<MaterialBean>()

        data.filter { it.orderStatus != 20 }.groupBy { it.orderId }.forEach {
            val materialBean = MaterialBean()
            materialBean.orderId = it.value[0].orderId
            materialBean.orderNumber = it.value[0].orderNumber
            materialBean.orderStatus = it.value[0].orderStatus
            materialBean.orderAmount = it.value[0].orderAmount
            val items = ArrayList<MaterialBean.Item>()
            for (i in it.value) {
                val item = MaterialBean.Item()
                item.consumables = i.consumables
                item.number = i.number
                items.add(item)
            }
            materialBean.items = items
            materialBeanArrayList.add(materialBean)
        }
        return materialBeanArrayList
    }

    /**
     *
     * 方法描述 隐藏手机号中间位置字符，显示前三后四个字符
     */
    fun hidePhoneNo(phoneNo: String): String {
        val length = phoneNo.length
        val beforeLength = 3
        val afterLength = 4
        val replaceSymbol = "*"
        val sb = StringBuffer()
        for (i in 0 until length) {
            if (i < beforeLength || i >= (length - afterLength)) {
                sb.append(phoneNo[i])
            } else {
                sb.append(replaceSymbol)
            }
        }
        return sb.toString()
    }
}